package com.demo.alternate_exchange;

import com.demo.commons.MqCons;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author shenguangyang
 */
@Component
public class NotRouteWarningListener {

    @RabbitListener(queues = MqCons.WARNING_QUEUE)
    public void onMessage(Channel channel, Message message) {
        try {
            System.out.println("报警发现不可路由信息: " + new String(message.getBody()));
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            try {
                channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
